package com.itheima.demo;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class UpdateDemo03 {
    public static void main(String[] args) throws Exception {
        //1.注册驱动(默认注册)
        Class.forName("com.mysql.jdbc.Driver");
        //2.获取连接
        //协议：// ip地址：端口号/请求资源  ( 本地IP＋端口号 localhost:3306 可用 / 代替)
        Connection conn = DriverManager.getConnection("jdbc:mysql://192.168.31.129:3306/demo3", "root", "root");
        //3.编写SQL语句
        String sql = "select * from stu";
        //4.创建编译对象
        Statement st = conn.createStatement();
        //5.执行SQL语句
        ResultSet res = st.executeQuery(sql);
        //6.遍历结果
        while (res.next()){

            System.out.println(res.getInt("id") + res.getString("name") + res.getString("phone"));
        }

        //释放资源
        res.close();
        st.close();
        conn.close();
    }
}
